#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

int main(int argc, char *argv[])
{
	// 生成指定数量的随机数并写入 CVS 文件
	FILE *fp = NULL;

	uint8_t fileName[20] = {0};
	uint32_t count = 0, Range = 0, base = 0;

	// 帮助描述
	if (argc < 4)
	{
		printf("Usage: <filename> <count> <base> <range>\nEx: %s 'pid' 1000 100 3\n", argv[0]);
		return 1;
	}

	// 解析命令行参数
	sprintf(fileName, "%s.csv", argv[1]);
	sscanf(argv[2], "%d", &count);
	sscanf(argv[3], "%d", &base);
	sscanf(argv[4], "%d", &Range);

	// 打开文件以写入随机数
	fp = fopen(fileName, "aw");
	if (fp == NULL)
	{
		printf("Error opening file!\n");
		return 1;
	}

	// 获取用户输入的随机数数量
	for (uint32_t i = 0; i < count; i++)
	{
		int random_number = rand() % Range;
		fprintf(fp, "0,%d.%d\n", base + random_number, rand() % 10000);
	}

	// 关闭文件并打印成功消息
	fclose(fp);

	printf("Random numbers generated and written to %s\n", fileName);
	return 0;
}